import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15

MainView {
    id: resetPanel
    width: 800
    height: 391
    property int resetType:0
    property int pwdTrue:-1
    property int deviceID:0
    Component.onCompleted: {
        //deviceIndex.model = getDeviceName();
        //deviceIndex.currentIndex=deviceID
        switch(pwdTrue){
            case 0:
                passwordFalse();
            break;
            case 1:
                passwordTrue();
                break;
            case -1:
                break;
        }
    }
    onPasswordTrue: {
        switch(resetType){
        case 0:
            if(mymodbus.resetCal()){
                resetPanelDialog.title=qsTr("校准复位成功！")
                resetPanelDialog.open();
            }
            else{
                resetPanelDialog.title=qsTr("校准复位失败！")
                resetPanelDialog.open();
            }
            break;
        case 1:
            if(mymodbus.resetPara()){
                resetPanelDialog.title=qsTr("参数复位成功！")
                resetPanelDialog.open();
            }
            else{
                resetPanelDialog.title=qsTr("参数复位失败！")
                resetPanelDialog.open();
            }
            break
//        case 2:
//            if(mymodbus.resetZeroValue()){
//                resetPanelDialog.title=qsTr("零值复位成功！")
//                resetPanelDialog.open();
//            }
//            else{
//                resetPanelDialog.title=qsTr("零值复位失败！")
//                resetPanelDialog.open();
//            }
//            break;
        case 3:
            if(mymodbus.resetAll()){
                resetPanelDialog.title=qsTr("全部复位成功！")
                resetPanelDialog.open();
            }
            else{
                resetPanelDialog.title=qsTr("全部复位失败！")
                resetPanelDialog.open();
            }
            break;
        }
    }
    onPasswordFalse: {
        resetPanelDialog.title=qsTr("密码错误！")
        resetPanelDialog.open();
    }
    function getDeviceName(){
        var devices=[]
        for(let i=0; i<mymodbus.axisCount; i++){
            devices.push(qsTr("轴")+(i+1).toString())
        }
        return devices;
    }
//    MyComboBox{
//                        id:deviceIndex
//                        x: 309
//                        y: 47
//                        width: 180
//                        height: 30
//                    }
    GridLayout{ //root中放置一个行布局，布局中放置3个方块
        id: resetlayout
        anchors.centerIn: parent
        //spacing: 3 //间距
        rows: 1 //行数
        columns: 3 //列数
        columnSpacing: 20
        Button
        {
            id:btnCalibrationReset
            x: 192
            y: 74
            Layout.row: 0
            Layout.column: 0
            Layout.preferredWidth: 185
            Layout.preferredHeight: 85
            background: Rectangle{
                border.width: 0
                color: "#7584C2"
                    }

            text: qsTr("校准复位")
            font.pixelSize: 25
            palette.buttonText: "white"
            //Connections {
            //           target: btnCalibrationReset
                       onClicked: {
                           resetType=0
                           //if(mytables.pwdSwitch===1){
//                           myLoader.visible=false;
//                           myLoader.visible=true
                               myLoader.setSource("EnterPwdPanel.qml", {"enterViewUrl":"ResetPanel.qml","lastViewUrl":"ResetPanel.qml","resetType":resetType,"deviceID":-1,"passwordType":1})
//                           }
//                           else{
//                               passwordTrue()
//                           }
                       }
            //}
        }
//        Button
//        {
//            id:btnParameterReset
//            x: 192
//            y: 74
//            Layout.row: 0
//            Layout.column: 1
//            Layout.preferredWidth: 185
//            Layout.preferredHeight: 85
//            background: Rectangle{
//                border.width: 0
//                color: "#7584C2"
//                    }

//            text: qsTr("参数复位")
//            font.pixelSize: 25
//            palette.buttonText: "white"
//            Connections {
//                       target: btnParameterReset
//                       onClicked: {
//                           resetType=1
////                           if(mytables.pwdSwitch===1){
////                           myLoader.visible=false;
////                           myLoader.visible=true
//myLoader.setSource("EnterPwdPanel.qml", {"enterViewUrl":"ResetPanel.qml","lastViewUrl":"ResetPanel.qml","resetType":resetType,"deviceID":-1,"passwordType":1})

////                           }
////                           else{
////                               passwordTrue()
////                           }
//                       }
//                   }
//        }
//        Button
//        {
//            id:btnSwitchReset
//            x: 431
//            y: 213
//            Layout.row: 2
//            Layout.column: 0
//            Layout.preferredWidth: 185
//            Layout.preferredHeight: 85
//            background: Rectangle{
//                border.width: 0
//                color: "#7584C2"
//                    }

//            text: qsTr("零值复位")
//            font.pixelSize: 25
//            palette.buttonText: "white"
//            Connections {
//                       target: btnSwitchReset
//                       onClicked: {
//                           resetType=2
//                           if(mytables.pwdSwitch === 1){
//myLoader.setSource("EnterPwdPanel.qml", {"enterViewUrl":"ResetPanel.qml","lastViewUrl":"ResetPanel.qml","resetType":resetType})
////                               myLoader.setsource="EnterPwdPanel.qml"
////                               var loadedItem = myLoader.item
////                               loadedItem.enterViewUrl="ResetPanel.qml"
////                               loadedItem.lastViewUrl="ResetPanel.qml"
//                           }
//                           else{
//                               passwordTrue()
//                           }
//                       }
//                   }
//        }
//        Button
//        {
//            id:btnAllhReset
//            x: 431
//            y: 213
//            Layout.row: 0
//            Layout.column: 2
//            Layout.preferredWidth: 185
//            Layout.preferredHeight: 85
//            background: Rectangle{
//                border.width: 0
//                color: "#7584C2"
//                    }

//            text: qsTr("全部复位")
//            font.pixelSize: 25
//            palette.buttonText: "white"
//            Connections {
//                       target: btnAllhReset
//                       onClicked: {                           rectangle.selectedView =7
//                           resetType=3
////                           if(mytables.pwdSwitch === 1){
////                           myLoader.visible=false;
////                           myLoader.visible=true
//myLoader.setSource("EnterPwdPanel.qml", {"enterViewUrl":"ResetPanel.qml","lastViewUrl":"ResetPanel.qml","resetType":resetType,"deviceID":-1,"passwordType":1})
////                           }
////                           else{
////                               passwordTrue()
////                           }
//                       }
//                   }
//        }
    }
    Button
    {
        id:btnReturn
        x: 688
        y: 281
        //x: 675
        //y: 20
        width: 100
        height: 100
        background: Rectangle{
            border.width: 0
            color: "#B0B0D0"
                }

        text: qsTr("返回")
        font.pixelSize: 25
        palette.buttonText: "white"
        Connections {
            target: btnReturn
            function onClicked() {
                //rectangle.selectedView = 2
//                myLoader.visible=false;
//                myLoader.visible=true
                myLoader.source="FunctionPanel.qml"
                bottomBar.selected=2
            }
        }
    }
    Dialog {
        anchors.centerIn: parent
        id: resetPanelDialog
        standardButtons: Dialog.Ok
        onAccepted: resetPanelDialog.close()
        z:100
    }
}

